<template>
	<view class="pages">
		
		<yy-uploadpictures :config='config' v-model="formData['images']">
			<view>
				<u--textarea v-model="formData.title" placeholder="用照片和祝福展示幸福时刻，记录幸福时刻，分享幸 福时刻" border="none" placeholderStyle="{color:'#B3B1B2';font-size:'28rpx'}" height="140"></u--textarea>
			</view>
		</yy-uploadpictures>
		<view class="btn_public">
			<u-button text="发布"
				customStyle="border-radius:46rpx;background:#FF7612;border:2rpx solid #FF7612;color:#fff"
				@click="submit" v-if="JSON.parse(formData.images).length>0||formData.desc!=''"></u-button>
			<u-button type="primary" disabled text="发布"
				customStyle="border-radius:46rpx;background:#D3D4D6;border:2rpx solid #D3D4D6;color:#fff" v-else>
			</u-button>
		</view>
	</view>
</template>

<script>
	import {saveCase} from '@/common/api.js'
	export default {
		data() {
			return {
				config: {
					id: 3,
					field: 'chunk',
					maxCount: 6,
					array: [],
					width: '202',
					height: '202',
					tip: '',
					slot:true,
				},
				formData: {
					title:'',
					images: '[]'
				}
			}
		},
		onLoad() {

		},
		methods: {
			return_beforePage() {
				let pages = getCurrentPages()
				if (pages.length > 0) {
					let beforePage = pages[pages.length - 2]
					// #ifdef H5
					beforePage.init_info()
					// #endif
					// #ifndef H5
					beforePage.$vm.init_info()
					// #endif
					uni.navigateBack()
				}else{
					uni.switchTab({
						url:'/pages/moment/index'
					})
				}
			},
			submit(){
			uni.showLoading({
					title: '发布中'
				});
					saveCase(this.formData, {
					custom: {
						auth: false,
						toast: false,
						catch: false
					}
				}).then((result) => {
						uni.$u.toast('发布成功')
					this.return_beforePage()
					
				}).catch((err) => {
					uni.hideLoading();
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.pages{
		background-color: #fff;
		height:100vh;
		
		/deep/ .main{
			padding:55rpx 48rpx;
			.long_title{
				font-size: 28rpx;
				font-family: Microsoft YaHei;
				font-weight: 400;
				color: #B3B1B2;
			}
		}
		.btn_public {
			position: fixed;
			bottom: 134rpx;
			left: 55rpx;
			right: 55rpx;
			line-height: 92rpx;
			overflow: hidden;
		}
	}
	
</style>
